-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix: force to decode as utf-8 when header contains application/json to avoid text garbling. #1700
Merged
wing328
merged 2 commits into
OpenAPITools:master
from
cimadai:enable_decode_as_utf8_when_header_contains_application_json
Jan 9, 2019
Merged
Bug fix: force to decode as utf-8 when header contains application/json to avoid text garbling. #1700
wing328
merged 2 commits into
OpenAPITools:master
from
cimadai:enable_decode_as_utf8_when_header_contains_application_json
Jan 9, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…o avoid text garbling. The original processing is using `response.body` to deserialize as json. However, this is decoded by latin1 if the header contains only "application/json" instead of "application/json; charset=utf-8". Because of this behavior, if the response body is encoded UTF-8 but the headers doesn't contain charset, the body will garbling. cf: dart-lang/http#175 Since playframework 2.6 returns "Content-Type: application/json" without "charset=utf-8", I changed this parsing algolithm.
…o avoid text garbling on error.
wing328
reviewed
Jan 2, 2019
/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8". | ||
String _decodeBodyBytes(Response response) { | ||
var contentType = response.headers['content-type']; | ||
if (contentType != null && contentType.contains("application/json")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the fix 👍 |
wing328
changed the title
fix: force to decode as utf-8 when header contains application/json to avoid text garbling.
Bug fix: force to decode as utf-8 when header contains application/json to avoid text garbling.
Jan 9, 2019
jimschubert
added a commit
to jimschubert/openapi-generator
that referenced
this pull request
Jan 9, 2019
* master: (52 commits) Support for "x-enum-descriptions" (OpenAPITools#1752) add new sample files Add a checklist to issue report (OpenAPITools#1851) Fix typo in template (OpenAPITools#1859) update samples add isModel to updatebooleanflagwithcodegenproperty (OpenAPITools#1844) [python-client] Add model default values (OpenAPITools#1776) fix: force to decode as utf-8 when header contains application/json to avoid text garbling. (OpenAPITools#1700) Better support for composed schema (allOf) (OpenAPITools#1842) Add additional properties to Java CodegenModel (OpenAPITools#1854) Minor Angular type improvements (OpenAPITools#1843) [DART] fix: set fields to null if json value is null. (OpenAPITools#1798) add options to maven plugin (OpenAPITools#1845) fix unqiue name in handling forward slash (OpenAPITools#1839) better handle of oauth (OpenAPITools#1838) [C] Support for authentication methods (OpenAPITools#1628) better error message when parameter ref not defined (OpenAPITools#1837) Add links to articles about openapi generator Add a link to @watiko article Delete langs command (OpenAPITools#1836) ...
A-Joshi
pushed a commit
to ihsmarkitoss/openapi-generator
that referenced
this pull request
Feb 27, 2019
…o avoid text garbling. (OpenAPITools#1700) * fix: force to decode as utf-8 when header contains application/json to avoid text garbling. The original processing is using `response.body` to deserialize as json. However, this is decoded by latin1 if the header contains only "application/json" instead of "application/json; charset=utf-8". Because of this behavior, if the response body is encoded UTF-8 but the headers doesn't contain charset, the body will garbling. cf: dart-lang/http#175 Since playframework 2.6 returns "Content-Type: application/json" without "charset=utf-8", I changed this parsing algolithm. * fix: force to decode as utf-8 when header contains application/json to avoid text garbling on error.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
The original processing is using
response.body
to deserialize as json inapi.mustache
.However, this is decoded by latin1 if the header contains only
application/json
instead ofapplication/json; charset=utf-8
.Because of this behavior, if the response body is encoded UTF-8 but the headers doesn't contain charset, the body will garbling.
cf: dart-lang/http#175
Since playframework 2.6 returns
Content-Type: application/json
withoutcharset=utf-8
, I changed this parsing algolithm.